<%@ page import="com.uni.entity.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  <title>闲优购-</title>

  <link rel="icon" href="img/weblogo.png" >
  <link rel="stylesheet" type="text/css" href="bootstrap-5.1.3-dist/css/bootstrap.min.css"/>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
  <link rel="stylesheet" type="text/css" href="css/ycc.css"/>
  <script type="text/javascript" src="js/jquery-3.6.0-min.js"></script>
  <script type="text/javascript" src="bootstrap-5.1.3-dist/js/bootstrap.min.js"></script>
  <script type="text/javascript" src="js/card_user_buy_record.js"></script>
<body>
<div style="margin-inline: auto">
  <h5>当前位置:用户管理>>管理用户</h5>
</div>

<div style="float: right;">
</div>
  <table class="table table-striped">
    <thead>
    <tr>
      <th>编号</th>
      <th>姓名</th>
      <th>联系方式</th>
      <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:set var="i" value="0" scope="page"></c:set>
    <c:forEach items="${sessionScope.userList}" begin="${(sessionScope.adminUserPage.pageNow-1) * 6}" var="user">
      <c:if test="${not empty user && i < sessionScope.adminUserPage.pageCount}">
        <tr><td>${user.id}</td>
          <td>${user.name}</td>
          <td>${user.phone}</td>
          <td>
            <button class="btn btn-danger btn-delete-user" data-href="/adminDeleteUser?id=${user.id}">删除</button>
          </td>
        </tr>
        <c:set var="i" value="${pageScope.i + 1}"></c:set>
      </c:if>
      </c:forEach>
    </tbody>
  </table>

  <c:if test="${not empty sessionScope.adminUserPage}">
    <c:set value="${sessionScope.adminUserPage}" var="page"/>
    <nav aria-label="Page navigation">
      共${page.totalRows} 条记录, ${page.pageNow} / ${page.totalPage}
      <ul class="pagination">
        <li class="page-item"><a class="page-link" href="/adminSelectAllUserPageable?page=${page.pageNow - 1}">上一页</a></li>
        <li class="page-item" style="margin-left: auto;"><a class="page-link" href="/adminSelectAllUserPageable?page=${page.pageNow + 1}">下一页</a></li>
      </ul>
    </nav>
  </c:if>
</body>
<script>
  $(document).ready(function(){
    $(".btn-delete-user").click(function (){
      var hf = $(this).data('href')
      $.ajax({
        url: hf,
        type: 'GET',
        async: false,
        error: function (){
          alert('AJAX请求错误')
        },
        success: function (res){
          if (res == "true")
            alert('删除成功!')
          else
            alert('删除失败.')
          window.location.href='/adminSelectAllUserPageable'
        }
      })

    });

  });
</script>
</html>
